package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.ChannelGroupJurisdictionAddDTO;
import org.jsola.hr.dto.ChannelGroupJurisdictionUpdateDTO;
import org.jsola.hr.entity.ChannelGroupJurisdictionDO;
import org.jsola.hr.query.ChannelGroupJurisdictionQuery;
import org.jsola.hr.service.IChannelGroupJurisdictionService;
import org.jsola.hr.vo.ChannelGroupJurisdictionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 渠道分组权限表
 *
 * @author zhr
 */
@Component
public class ChannelGroupJurisdictionTestHelper extends BaseTestHelper {
    
    @Autowired
    private IChannelGroupJurisdictionService channelGroupJurisdictionService;

    /**
     * 生成add测试数据
     * @return ChannelGroupJurisdictionAddDTO
     */
    public ChannelGroupJurisdictionAddDTO getChannelGroupJurisdictionAddDTO(){
        ChannelGroupJurisdictionAddDTO channelGroupJurisdictionAddDTO = new ChannelGroupJurisdictionAddDTO();
        channelGroupJurisdictionAddDTO.setUserId(getRandomValue("varchar",32));
        channelGroupJurisdictionAddDTO.setJurisdiction(SafeKit.getInteger(getRandomValue("int",1)));
        return channelGroupJurisdictionAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ChannelGroupJurisdictionUpdateDTO
     */
    public ChannelGroupJurisdictionUpdateDTO getChannelGroupJurisdictionUpdateDTO(ChannelGroupJurisdictionVO channelGroupJurisdictionVO){
        return channelGroupJurisdictionService.selectDOById(channelGroupJurisdictionVO.getId(), SITE_ID).to(ChannelGroupJurisdictionUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ChannelGroupJurisdictionQuery
     */
    public ChannelGroupJurisdictionQuery getChannelGroupJurisdictionQuery() {
        ChannelGroupJurisdictionQuery channelGroupJurisdictionQuery = new ChannelGroupJurisdictionQuery();
        List<ChannelGroupJurisdictionDO> channelGroupJurisdictionDOList = channelGroupJurisdictionService.list(new ChannelGroupJurisdictionDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(channelGroupJurisdictionDOList)) {
            ChannelGroupJurisdictionDO channelGroupJurisdictionDO = channelGroupJurisdictionDOList.get(0);
            channelGroupJurisdictionQuery = channelGroupJurisdictionDO.to(ChannelGroupJurisdictionQuery.class);
        }
        return channelGroupJurisdictionQuery;
    }

    /**
     * 保存示例
     * @return ChannelGroupJurisdictionVO
     */
    public ChannelGroupJurisdictionVO saveChannelGroupJurisdictionExample(){
        ChannelGroupJurisdictionAddDTO addDTO = this.getChannelGroupJurisdictionAddDTO();
        ChannelGroupJurisdictionVO channelGroupJurisdictionVO = channelGroupJurisdictionService.save(addDTO,buildTokenUser());
        return channelGroupJurisdictionVO;
    }


}

